class UnionFind {
    private final int[] father;

    public UnionFind(int n) {
        father = new int[n];
        for (int i = 0; i < n; i++) {
            father[i] = i;
        }
    }

    public boolean isSame(int u, int v)  {
        u = find(u);
        v = find(v);
        return u == v;
    }

    private int find(int u) {
        if (u == father[u]) {
            return u;
        }
        father[u] = find(father[u]);
        return father[u];
    }

    public void join(int u, int v) {
        u = find(u);
        v = find(v);
        if (u == v) {
            return;
        }
        father[v] = u;
    }
}

class Solution {
    public boolean validPath(int n, int[][] edges, int source, int destination) {
        UnionFind union = new UnionFind(n);
        for (int[] edge : edges) {
            int r = edge[0];
            int c = edge[1];
            union.join(r, c);
        }
        return union.isSame(source, destination);
    }
}

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}